package com.youi.shop.commons.exceptions;

import com.youi.shop.commons.result.StatusCode;

/**
 * @version 1.0
 * @Author: xxf
 * @CreateDate: 2020/11/9 15:30
 */
public class GlobalException extends RuntimeException {
    private static final long serialVersionUID = 1L;

    /**
     * 错误码
     */
    protected int errorCode = StatusCode.SERVICE_ERROR.getStatus();
    /**
     * 错误信息
     */
    protected String errorMsg;

    public GlobalException() {
        super();
    }

    public GlobalException(StatusCode status) {
        super(Integer.toString(status.getStatus()));
        this.errorCode = status.getStatus();
        this.errorMsg = status.getMessage();
    }

    public GlobalException(StatusCode status, Throwable cause) {
        super(Integer.toString(status.getStatus()), cause);
        this.errorCode = status.getStatus();
        this.errorMsg = status.getMessage();
    }

    public GlobalException(String errorMsg) {
        super(errorMsg);
        this.errorMsg = errorMsg;
    }

    public GlobalException(int errorCode, String errorMsg) {
        super(Integer.toString(errorCode));
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
    }

    public GlobalException(int errorCode, String errorMsg, Throwable cause) {
        super(Integer.toString(errorCode), cause);
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
    }


    public int getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(int errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    @Override
    public String getMessage() {
        return errorMsg;
    }

    @Override
    public Throwable fillInStackTrace() {
        return this;
    }
}
